<template>
  <div class="header_right_lang">
    <div class="header_right_btn" @click="show = !show">
      <img :src="userInfo.avatar" />
      <span style="margin-left: 0.25rem">{{ userInfo.nick_name }}</span>
      <div class="icon"></div>
    </div>
    <div class="header_right_langList" v-show="show">
      <div
        class="header_right_langItem"
        v-for="item in list"
        :key="item.value"
        @click="maskItemClick(item)"
      >
        <span>{{ item.name }}</span>
      </div>
    </div>
    <el-dialog
      v-model="passwordShow"
      width="32.25rem"
      destroy-on-close
      :title="$t('修改密码')"
      center
    >
      <div>
        <div class="item">
          <div class="item_title">{{ $t("类型") }}</div>
          <div class="item_group">{{ $t("交易密码") }}</div>
        </div>
        <div class="item">
          <div class="item_title">{{ $t("旧密码") }}</div>
          <div class="item_group">
            <el-input
              type="password"
              v-model="password"
              :placeholder="$t('输入旧密码')"
            ></el-input>
          </div>
        </div>
        <div class="item">
          <div class="item_title">{{ $t("新密码") }}</div>
          <div class="item_group">
            <el-input
              type="password"
              v-model="newPassword"
              :placeholder="$t('输入新密码')"
            ></el-input>
          </div>
        </div>
      </div>
      <template #footer>
        <span class="dialog-footer">
          <el-button class="btn" @click="closePassword">{{ $t("取消") }}</el-button>
          <el-button class="btn" type="primary" @click="changePassword"
            >{{ $t("更新") }}
          </el-button>
        </span>
      </template>
    </el-dialog>
    <el-dialog
      v-model="infoShow"
      width="32.25rem"
      destroy-on-close
      :title="$t('资讯')"
      center
    >
      <div>
        <div class="form">
          <div class="form_item">
            <div class="item_title">{{ $t("客户名称") }}</div>
            <div class="item_data">{{ userInfo.nick_name || "--" }}</div>
          </div>
          <!-- <div class="form_item">
            <div class="item_title">客户账户</div>
            <div class="item_data">交易密码</div>
          </div> -->
          <div class="form_item">
            <div class="item_title">{{ $t("平台公司名") }}</div>
            <div class="item_data">{{ setting.site_name || "--" }}</div>
          </div>
          <!-- <div class="form_item">
            <div class="item_title">地址</div>
            <div class="item_data">交易密码</div>
          </div> -->
          <div class="form_item">
            <div class="item_title">{{ $t("电话") }}</div>
            <div class="item_data">{{ userInfo.phone || "--" }}</div>
          </div>
          <div class="form_item last_item">
            <div class="item_title">Email</div>
            <div class="item_data">{{ userInfo.email || "--" }}</div>
          </div>
        </div>
      </div>
      <template #footer>
        <span class="dialog-footer">
          <el-button
            class="btn"
            style="width: 130px"
            type="primary"
            @click="infoShow = false"
          >
            {{ $t("关闭") }}
          </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { changeApi } from "@/api/index";
import { ElNotification } from "element-plus";
export default {
  name: "LoginPage",
  props: ["userInfo", "setting"],
  data() {
    return {
      show: false,
      list: [
        {
          name: this.$t("修改密码"),
          value: "password",
        },
        {
          name: this.$t("资讯"),
          value: "news",
        },
        {
          name: this.$t("退出"),
          value: "logout",
        },
      ],
      passwordShow: false,
      password: "",
      newPassword: "",
      infoShow: false,
    };
  },
  methods: {
    userLogout() {
      this.$store.commit("user/USER_LOGOUT");
    },
    maskItemClick(item) {
      this.show = false;
      if (item.value === "logout") {
        this.userLogout();
      }
      if (item.value == "password") {
        this.passwordShow = true;
      }
      if (item.value == "news") {
        this.infoShow = true;
      }
    },
    closePassword() {
      this.passwordShow = false;
      this.password = "";
      this.newPassword = "";
    },
    changePassword() {
      changeApi({
        token: localStorage.getItem("token"),
        old_pass: this.password,
        new_pass: this.newPassword,
      }).then((res) => {
        console.log(res);
        if (res.code == 1) {
          ElNotification({
            message: res.msg,
            type: "success",
          });
          this.closePassword();
        } else {
          ElNotification({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.header_right_lang {
  position: relative;
  border-radius: 15px;

  .header_right_btn {
    display: flex;
    align-items: center;
    justify-content: space-around;
    cursor: pointer;
    color: #ddd;
    padding: 0 12px 0 0;
    border-radius: 40px;
    background-color: #22252f;
    height: 36px;
    img {
      height: 2.25rem;
      width: 2.25rem;
      border-radius: 50%;
    }
    .icon {
      width: 10px;
      height: 6px;
      clip-path: polygon(0 0, 50% 100%, 100% 0);
      background: #ddd;
      margin: 0 0.25rem 0 0.5rem;
    }
  }

  .header_right_langList {
    position: absolute;
    will-change: transform;
    top: 0px;
    left: -31px;
    bottom: auto;
    right: 0;
    transform: translate(0, 36px);
    background-color: #2d303d;
    margin-top: 10px;
    box-shadow: 0 0.5rem 1.5rem 0.5rem rgba(0, 0, 0, 0.15);
    border-radius: 0.5rem;
    padding: 0.5rem 0;
    font-size: 0.8125rem;
    z-index: 1060;
    .header_right_langItem {
      padding: 0.3125rem 0.9375rem 0.8125rem;
      margin-bottom: 0.5rem;
      border-bottom: 1px solid #272b37;
      font-size: 0.8125rem;
      font-weight: 400;
      text-align: center;
    }
    &:after {
      position: absolute;
      content: "";
      width: 0;
      height: 0;
      border-style: solid;
      border-width: 6px;
      border-color: transparent transparent #2d303d transparent;
      right: 20px;
      top: -12px;
    }
    &:hover {
      .header_right_langItem {
        color: #fff;
        cursor: pointer;
      }
    }

    .header_right_btn:hover {
      background-color: #f6d39c;
      color: black;
    }

    .active {
      background-color: rgba($color: #04d1b3, $alpha: 0.1);

      & > img {
        width: 17px;
        height: 17px;
        margin-right: 3px;
      }

      & > span {
        font-weight: 600;
      }
    }
  }
}
.item {
  color: #eee;
  padding-top: 0.25rem;
  margin-bottom: 0.5rem;
  .item_title {
    color: #cbd1e8;
  }
  .item_group {
    margin-top: 0.5rem;
    padding: 0 10px;
    background-color: #303443;
    border-radius: 5px;
    line-height: 50px;
  }
}
::v-deep(.el-dialog) {
  margin: 0;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: #3a3f50;
  .el-dialog__header {
    text-align: left;
  }
  // transform: translateY(-50%);
  .el-dialog__title {
    display: inline-block;
    color: #fff;
    width: 100%;
    text-align: left;
  }
  .el-dialog__body {
    padding: 1rem;
  }
}
.dialog-footer {
  .btn {
    text-align: center;
    font-size: 16px;
    line-height: 50px;
    border-radius: 5px;
    width: 186px;
    height: 50px;
    background: #fff;
    border: none;
    box-shadow: none;
    color: #22252f;
    &:hover {
      color: #22252f;
    }
  }
  .el-button--primary {
    background: linear-gradient(81deg, #f7d8a7 0%, #f4cc8c 100%);
  }
}
.form {
  // border: 1px solid #303443;
  .form_item {
    display: flex;
    align-items: center;
    color: #fff;
    .item_title {
      background-color: rgba(0, 0, 0, 0.05);
      width: 120px;
      padding: 0.625rem 0.75rem;
      border-top: 1px solid #303443;
      border-left: 1px solid #303443;
      text-align: right;
    }
    .item_data {
      flex: 1;
      padding: 0.625rem 0.75rem;
      border-top: 1px solid #303443;
      border-left: 1px solid #303443;
      border-right: 1px solid #303443;
    }
  }
  .last_item {
    .item_title {
      border-bottom: 1px solid #303443;
    }
    .item_data {
      border-bottom: 1px solid #303443;
    }
  }
}
</style>
